﻿using PlayerRoles;
using PluginAPI.Core.Attributes;
using PluginAPI.Enums;
using PluginAPI.Events;
using Utils;



namespace RoleCustom.Event
{
    public class PlayerEvent
    {
        [PluginEvent(ServerEventType.PlayerSpawn)]
        public void OnPlayerSpawn(PlayerSpawnEvent ev)
        {
            TimeCoroutine.Delay(0.5f, () =>
            {
                if (ev.Player.Team == Team.SCPs)
                {
                    ev.Player.ReferenceHub.serverRoles.SetColor("red");
                    ev.Player.ReferenceHub.serverRoles.SetText("SCP");
                    return;
                }

                if (ev.Player.Team == Team.OtherAlive)
                {
                    ev.Player.ReferenceHub.serverRoles.SetColor("grey");
                    ev.Player.ReferenceHub.serverRoles.SetText("100 经验包 | 击杀我获取");
                    return;
                }

                if (ev.Player.Team == Team.FoundationForces ||
                    ev.Player.Team == Team.Dead ||
                    ev.Player.Team == Team.ChaosInsurgency)
                {
                    ev.Player.ReferenceHub.serverRoles.SetColor("grey");
                    ev.Player.ReferenceHub.serverRoles.SetText("");
                }
            });
        }



        [PluginEvent(ServerEventType.PlayerSpawn)]
        public void OnPlayerAddAmmo(PlayerSpawnEvent ev)
        {
            TimeCoroutine.Delay(5f, () =>
            {
                if (ev.Player.Role == RoleTypeId.ClassD) return;
                if (ev.Player.Role == RoleTypeId.Scientist) return;
                if (ev.Player.IsSCP) return;

                PlayerUtils.AddAmmo(ev.Player);
            });
        }

        [PluginEvent(ServerEventType.PlayerChangeRole)]
        public void OnPlayerChangedRole(PlayerChangeRoleEvent ev)
        {
            PlayerUtils.SetDefaultHP(ev.Player);

            if (ev.NewRole == RoleTypeId.Scp0492)
            {
                PlayerUtils.SetHP(ev.Player,
                    RoleCustom.Main.CodeLoad.Singleton.Config.SCP0492Event.Health,
                   RoleCustom.Main.CodeLoad.Singleton.Config.SCP0492Event.Health);

                PlayerUtils.SetAP(ev.Player,
                    RoleCustom.Main.CodeLoad.Singleton.Config.SCP0492Event.AHealth,
                    RoleCustom.Main.CodeLoad.Singleton.Config.SCP0492Event.AHealth);
            }
        }


        [PluginEvent(ServerEventType.PlayerDeath)]
        public void OnPlayerDeath(PlayerDeathEvent e)
        {
            TimeCoroutine.Delay(0.3f, () =>
            {
                e.Player.ReferenceHub.serverRoles.SetColor("grey");
                e.Player.ReferenceHub.serverRoles.SetText("");
            });
        }


        //[PluginEvent(ServerEventType.PlayerReloadWeapon)]
        //public void OnPlayerReload(PlayerReloadWeaponEvent ev)
        //{
        //    switch (ev.Firearm.ItemTypeId)
        //    {

        //        case ItemType.GunA7:
        //        case ItemType.GunLogicer:
        //        case ItemType.GunAK:
        //            ev.Player.AddItem(ItemType.Ammo762x39);
        //            break;

        //        case ItemType.GunE11SR:
        //        case ItemType.GunFRMG0:
        //            ev.Player.AddAmmo(ItemType.Ammo556x45, 75);
        //            break;

        //        case ItemType.GunCOM15:
        //        case ItemType.GunCOM18:
        //        case ItemType.GunFSP9:
        //        case ItemType.GunCrossvec:
        //        case ItemType.GunCom45:
        //            ev.Player.AddAmmo(ItemType.Ammo9x19, 75);
        //            break;

        //        case ItemType.GunShotgun:
        //            ev.Player.AddAmmo(ItemType.Ammo12gauge, 75);
        //            break;

        //        case ItemType.GunRevolver:
        //            ev.Player.AddAmmo(ItemType.Ammo44cal, 75);
        //            break;
        //    }
        //}
    }
}
